#ifndef HRVANA_H
#define HRVANA_H

#include <Q3DSurface>
#include <QWidget>
#include <Utils/arrayoperation.h>
#include <Utils/lfhfplot.h>
#include <Utils/timefreqspectrogramplot.h>
#include <EctopicPro/OutlierDetector.h>
#include <EctopicPro/replaceOutliers.h>
#include <HRVCompute/coder_array.h>
#include <HRVCompute/freqDomainHRV_types.h>
#include <QChartViews/surfacegraphmodifier.h>
#include <mentalPressure/mentpressurecomp.h>
#include "Utils/histogram.h"



QT_BEGIN_NAMESPACE
namespace Ui {
class HRVAna;
}
QT_END_NAMESPACE

class HRVAna : public QWidget
{
    Q_OBJECT

public:
    HRVAna(QWidget *parent = nullptr);
    ~HRVAna();


private slots:
    void on_pushButton_exit_clicked();

    void on_pushButton_ReadRawRR_clicked();

    void on_pb_TimeDomain_clicked();
    void on_pb_FreqDomain_clicked();
    void on_pb_Scatter_clicked();
    void on_pb_NonLinearDomain_clicked();
    void on_pb_TimeFreqDomain_clicked();
    void on_pb_MentalPressure_clicked();
    void on_pb_Nerval_clicked();
    void on_pushButton_startComp_clicked();


    void on_comboBox_tf_type_currentIndexChanged(int index);

    void on_comboBox_surf_currentIndexChanged(int index);

    void on_lineEdit_age_textEdited(const QString &arg1);

    void on_comboBox_sex_currentIndexChanged(int index);

    void on_comboBox_mp_currentIndexChanged(int index);

private:
    Ui::HRVAna *ui;
    QVector<double>rawRRData_x,rawRRData_y;
    QVector<double>proRRData_x,proRRData_y;

    int rawrr_Len;
    struct9_T output_tf;
    QVector<double>burg_t,burt_f;
    QVector<QVector<double>>burg_psd;
    QVector<double>lomb_t,lomb_F;
    QVector<QVector<double>>lomb_PSD;
    QVector<double>wav_t,wav_F;
    QVector<QVector<double>>wav_PSD;
    QVector<int>Ectopic_pos;//异位信息
    QVector<bool>Ectopic_b;
    void initRRCurve();
    void initQcustomPlots();
    void UpdateRRGraph(QVector<double> x, QVector<double> y);
    void ReadRawRRData();
    void initControls();
    void ReplaceEctopicPro();
    void UpdateRRGraph();
    void EctopicPro(bool b_p, bool b_sd, bool b_median);
    void ComputeHRV();
    coder::array<double, 2U> transData(QVector<double> proRR_x, QVector<double> proRR_y,bool isSecond);
    void ProHistogram_RR();
    void ProHistogram_HR();
    Histogram histogram_RR,histogram_HR;
    void initScatter();
    void ComputeNonLinearIndex();
    void initDFACurve();
    TimeFreqSpectrogramPlot *timeFreqSpectrogramPlot_burg,*timeFreqSpectrogramPlot_wavelet,*timeFreqSpectrogramPlot_lomb;
    Q3DSurface *graph;
    QWidget *container;
    SurfaceGraphModifier *modifier;
    void init3DSurf();
    void getTimeFreqGlobalData(struct9_T output_tf);
    void getLFHF(struct9_T output_tf,bool isratio);
    LFHFPlot *lfhf_burg,lfhf_lomb,lfhf_wav;
    MentPressureComp *mentPressureComp;
    void getMpInfo(struct9_T output_tf,int type);
};
#endif // HRVANA_H
